{% extends "layout.html" %}

{% from "macros/general.html" import
        set_account_status_img,
        highlight_username_in_mail,
        set_admin_type_img,
        show_pages,
        with context
        %}
{% from "macros/msgHandlers.html" import adminMsgHandler with context %}

{% block title %}{{ _('Domain Admins') }}{% endblock %}
{% block navlinks_active_admins %}class="active"{% endblock %}

{% block main %}
{# Show system message #}
{{ adminMsgHandler(msg) }}

{# List admins #}

{#{% if admins|length > 0 %}#}
{% if admins is not string %}
    <div class="content-box">
        <div class="box-body">
            <div class="box-header clear">
                {# -- Tabs -- #}
                <ul class="tabs clear">
                    <li class="active"><a href="{{ctx.homepath}}/admins">{{ _('All admins') }}</a></li>
                    {% if session.get('domainGlobalAdmin') is sameas true %}
                        <li><a href="{{ctx.homepath}}/create/admin"><img src="{{ctx.homepath}}/static/{{skin}}/images/ico_add_12.png" class="vcenter" />&nbsp;{{ _('Add admin') }}</a></li>
                    {% endif %}
                </ul>

                <h2>{{ _('All mail administrators.') }}
                    {% if total is defined and admins|length > 0 %}
                        ({{ (cur_page-1) * session['pageSizeLimit'] + 1 }}-{{ (cur_page-1) * session['pageSizeLimit'] + admins|length}}/{{ total }})
                    {% endif %}
                </h2>
            </div>

        <form id="list_table" method="post" action="{{ctx.homepath}}/admins">
        <table class="style1 tablesorter" cellspacing="0">
        <thead>
        <tr>
            <th class="checkbox"><input type="checkbox" class="checkbox select-all" /></th>
            <th>{{ _('Display Name') }}</th>
            <th>{{ _('Mail Address') }}</th>
            <th>{{ _('Global Admin') }}</th>
            <th>{{ _('Created') }}</th>
        </tr>
        </thead>

        <tbody>
            {% for r in admins %}
                {% set username = r.username |e %}
                {% set name = r.name |e %}

                <tr>
                    <td class="checkbox"><input type="checkbox" name="mail" value="{{ username }}" {% if username == session.get('username') %}disabled{% endif %}/></td>
                    <td>
                        <a href="{{ctx.homepath}}/profile/admin/general/{{ username }}"><img src="{{ctx.homepath}}/static/{{skin}}/images/action_edit.png" title="{{ _('Edit account profile') }}" class="fr-space"/></a>
                        {{ set_account_status_img(r.active) }}

                        {# -- Show name -- #}
                        {% if name == '' %}
                            {{ username.split('@', 1)[0] }}
                        {% else %}
                            {{ name |cutString }}
                        {% endif %}
                    </td>
                    <td>{{ username }}</td>
                    {% if username in allGlobalAdmins %}
                        <td>{{ set_admin_type_img('yes') }}</td>
                    {% else %}
                        <td>{{ set_admin_type_img('no') }}</td>
                    {% endif %}
                    <td>{{ r.created |setDatetimeFormat(hour=False) }}</td>
                </tr>
            {% endfor %}
        </tbody>
        </table>

        <div class="tab-footer clear f1">
            <div class="fl">
                <select name="action" class="fl-space">
                    <option>{{ _('Choose Action') }}</option>
                    <option value="enable">{{ _('Enable') }}</option>
                    <option value="disable">{{ _('Disable') }}</option>
                    <option value="delete">{{ _('Delete') }}</option>
                </select>
                <input type="submit" value="{{ _('Apply') }}" class="button fl-space" />
            </div>

            {% set pages = show_pages(
                  baseurl=ctx.homepath + '/admins',
                  total=total,
                  cur_page=cur_page)
                  %}

            {{ pages }}
        </div>
        </form>

    </div>{# -- box body -- #}
</div>{# -- content box -- #}
{% endif %}

{% endblock main %}

{% block js %}
    {{ load_jquery(['tablesorter'], sortFirstCol=false) }}
{% endblock js %}
